import java.util.List;

public class Main {
    public static void main(String[] args) {
        // 获取LoadBalancer的单例实例
        LoadBalancer loadBalancer = LoadBalancer.getLoadBalancer();

        // 创建一些服务器实例
        Server server1 = new Server();
        server1.setIP("192.168.1.1");
        server1.setName("Server1");
        server1.setPort(8080);
        server1.setStatus(true);
        server1.setConnections(10);

        Server server2 = new Server();
        server2.setIP("192.168.1.2");
        server2.setName("Server2");
        server2.setPort(8081);
        server2.setStatus(true);
        server2.setConnections(5);

        Server server3 = new Server();
        server3.setIP("192.168.1.3");
        server3.setName("Server3");
        server3.setPort(8082);
        server3.setStatus(true);
        server3.setConnections(20);

        // 添加服务器到负载均衡器
        loadBalancer.addServer(server1);
        loadBalancer.addServer(server2);
        loadBalancer.addServer(server3);

        // 获取并打印服务器列表
        System.out.println("负载均衡器中的服务器列表:");
        List<Server> servers = loadBalancer.getServerList();
        for (Server server : servers) {
            System.out.println("名称: " + server.getName() + ", IP地址: " + server.getIP() + ", 端口: " + server.getPort() + ", 连接数: " + server.getConnections() + ", 状态: " + server.getStatus());
        }

        // 获取连接数最少的服务器
        Server selectedServer = loadBalancer.getServer();
        System.out.println("\n连接数最少的服务器:");
        System.out.println("名称: " + selectedServer.getName() + ", IP地址: " + selectedServer.getIP() + ", 端口: " + selectedServer.getPort() + ", 连接数: " + selectedServer.getConnections() + ", 状态: " + selectedServer.getStatus());

        // 移除一个服务器
        loadBalancer.removeServer(server1.getIP());
        System.out.println("\n移除Server1后，负载均衡器中的服务器列表:");
        servers = loadBalancer.getServerList();
        for (Server server : servers) {
            System.out.println("名称: " + server.getName() + ", IP地址: " + server.getIP() + ", 端口: " + server.getPort() + ", 连接数: " + selectedServer.getConnections() + ", 状态: " + server.getStatus());
        }
    }
}
